//将表单序列化为JSON
$.fn.serializeObject = function(){    
   var o = {};    
   var a = this.serializeArray();    
   $.each(a, function() {    
       if (o[this.name]) {    
           if (!o[this.name].push) {    
               o[this.name] = [o[this.name]];    
           }    
           o[this.name].push(this.value || '');    
       } else {    
           o[this.name] = this.value || '';    
       }    
   });    
   return o;    
};  
//毫秒转换成置顶日期格式
var format = function(time, format){
    var t = new Date(time);
    var tf = function(i){return (i < 10 ? '0' : '') + i};
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
        switch(a){
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return tf(t.getMinutes());
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return tf(t.getHours());
                break;
            case 'ss':
                return tf(t.getSeconds());
                break;
        }
    })
}

// dataTables 引用
/***
 * contId:dataTables 的ID
 * url：请求的链接
 * listArr: 对象拼接
 * 
 */
function matchTable(contId, url, listArr, funParam, destorys) {
	if(destorys){
		if($.fn.dataTable.isDataTable(contId)){
	        _table = $(contId).DataTable();
	        _table.destroy();
		}
	}
    //初始化表格
    var table = $(contId).DataTable(
            {
            	"scrollX": true,
            	"bServerSide": true,
                "ordering": false,
                "searching": false,
                "bLengthChange": true,
                "pagingType": "full_numbers",
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项结果",
                    "sZeroRecords": "没有匹配结果",
                    "bPaginate": true,
                    "bFilter": true,
                    "sInfo": "显示第  _START_ 至  _END_ 项结果，共  _TOTAL_ 项，当前位置  第_PAGE_页",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由  _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "表中数据为空",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    }
                },
                "bDeferRender": false,
                "retrieve": true,
                "processing": true,
                "ajax": {
                    url: webroot + url,
                    type: "POST",
                    data: funParam
                },
                "columns": listArr
            });
    return table;
}

//返回行数据 为object对象
//tableObj datatables对象 trObj tr对象
function getValueToTableByKey(tableObj, trObj){
	return tableObj.row(trObj).data();
}